package com.yswl.yeeduo.view.dialog;

import android.app.AlertDialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.yswl.yeeduo.R;

public class ComfireAlertDialog extends AlertDialog implements View.OnClickListener {
	private static final String TAG = "ComfireAlertDialog";
	public TextView comfire_alert_msg;
	public Button sureBt;
	public Button cancelBt;

	public ComfireAlertDialog(Context context) {
		super(context);
		init(context);
	}

	public ComfireAlertDialog(Context context, boolean cancelable, OnCancelListener cancelListener) {
		super(context, cancelable, cancelListener);
		init(context);
	}

	public ComfireAlertDialog(Context context, int theme) {
		super(context, theme);
		init(context);
	}

	private void init(Context context) {
		View ui = LayoutInflater.from(context).inflate(R.layout.dialog_comfire_alert, null);
		this.setView(ui);
		comfire_alert_msg = (TextView) ui.findViewById(R.id.comfire_alert_msg);
		cancelBt = (Button) ui.findViewById(R.id.comfire_alert_cancel);
		sureBt = (Button) ui.findViewById(R.id.comfire_alert_sure);

		cancelBt.setOnClickListener(this);
		sureBt.setOnClickListener(this);
	}

	ComfireAlertDialogListner ls;

	public void setComfireAlertDialogClick(ComfireAlertDialogListner ls) {
		this.ls = ls;
	};

	public interface ComfireAlertDialogListner {
		public void ComfireAlertDialogSure(int targetId, AlertDialog dialog, Object param);

		public void ComfireAlertDialogCancel(int targetId, AlertDialog dialog);
	}

	@Override
	public void onClick(View v) {
		int id = v.getId();
		switch (id) {
		case R.id.comfire_alert_cancel:
			if (ls != null) {
				ls.ComfireAlertDialogCancel(targetId, this);
			}
			break;
		case R.id.comfire_alert_sure:
			if (ls != null) {
				ls.ComfireAlertDialogSure(targetId, this, mParamObj);
			}
			break;
		default:
			break;
		}
	}

	public int targetId = 0;

	public int getTargetId() {
		return targetId;
	}

	public Object mParamObj;

	public void setTarget(int targetId, Object params) {
		this.targetId = targetId;
		this.mParamObj = params;
	}

	public String title;
	public String msg;

	public static ComfireAlertDialog getComfireAlertDialog(Context context, ComfireAlertDialogListner ls, int targetId, Object params, String msg) {
		ComfireAlertDialog d = new ComfireAlertDialog(context);
		d.setComfireAlertDialogClick(ls);
		d.setTarget(targetId, params);
		d.comfire_alert_msg.setText(msg);
		return d;
	}

	public static ComfireAlertDialog getComfireAlertDialog(Context context, ComfireAlertDialogListner ls, int targetId, Object params, String msg, String no, String yes) {
		ComfireAlertDialog d = new ComfireAlertDialog(context);
		d.setComfireAlertDialogClick(ls);
		d.setTarget(targetId, params);
		d.comfire_alert_msg.setText(msg);
		d.cancelBt.setText(no);
		d.sureBt.setText(yes);
		return d;
	}
}
